package com.zzty.serviceimpl;

import com.zzty.common.Split;
import com.zzty.dao.*;
import com.zzty.daoimpl.*;
import com.zzty.entity.Groups;
import com.zzty.entity.TeamExam;
import com.zzty.entity.User;
import com.zzty.service.TeamExamService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


public class TeamExamServiceImpl implements TeamExamService {
    QuestionDao qd=new QuestionDaoImpl();
    TeamExamDao ted=new TeamExamDaoImpl();
    UserDao ud=new UserDaoImpl();
    Split sp=new Split();
    TeamExamTransactionDao tetd=new TeamExamTransactionDaoImpl();

    public String getContentByDate(String date,Integer classId){
        String questionId=ted.getQuestionIdByDate(date,classId);
        String content = "";
        if(questionId!=null) {
            List<Integer> questionIds = sp.getSplit(questionId);
            for (Integer qId : questionIds) {
                content += (qd.getContentById(qId) + "\n");
            }
        }
        return content==""?null:content;
    }
    public List getTeamExamToTable(){
        List<TeamExam> teamExams=null;
        if(ted.getTeamExamToTable()==null){
            return null;
        }else{
            teamExams=ted.getTeamExamToTable();
        }
        return teamExams;
    }
    public boolean checkDate(String date){
        boolean result=ted.checkDate(date);
        return result;
    }
    public Integer getIdByDate(){
        Integer id=null;
        Date d=new Date();//获取时间
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String today=sdf.format(d);
        if(ted.getIdByDate(today)!=null) {
            id = ted.getIdByDate(today);
        }
        return id;
    }
    public boolean setWinnersByDate(String date,String name1,String name2){
        boolean result=false;
        User user1=new User();
        User user2=new User();
        try {
            user1=ud.searchUserByName(name1);
            user2=ud.searchUserByName(name2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        result=ted.setWinnersByDate(date,user1.getId(),user2.getId());
        return result;
    }
    public List getWinnerIdByDate(String date){
        List<Integer> winnerIds=ted.getWinnerIdByDate(date);
        return winnerIds;
    }




}
